package com.yanqu.road.server.cmd.activity.unionwar;

import com.yanqu.road.entity.activity.unionwar.result.CurrentTimeInfo;
import com.yanqu.road.pb.activity.unionwar.UnionWarActivityServerProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.unionwar.UnionPhaseWarMgr;
import com.yanqu.road.server.manger.activity.unionwar.UnionWar;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.manger.union.GameUnionActivityGroupMgr;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.string.StringUtils;

@Cmd(code = GameProtocol.S_UNION_WAR_PREPARE_BATTLE_DATA_STATISTICS, desc = "战斗数据统计")
public class UnionBattleDataStatisticsReqCmd extends AbstractCommand {

    private int activityId;
    private int phase;
    private int session;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        UnionWarActivityServerProto.UnionBattleDataStatisticsReqMsg reqMsg = UnionWarActivityServerProto.UnionBattleDataStatisticsReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        phase = reqMsg.getPhase();
        session = reqMsg.getSession();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        UnionWar unionWar = UnionPhaseWarMgr.getUnionWarMap().get(activityId);
        //player.getUserInfo().getUnionUid();
        String unionUid = UnionWar.getUserUnionUid(activityId, player.getUserInfo());
        if(unionWar != null && !StringUtils.isNullOrEmpty(unionUid)) {
        int groupId = GameUnionActivityGroupMgr.getGroupId(activityId, unionUid);
            CurrentTimeInfo currentTimeInfo = unionWar.getCurrentTimeInfo();
            if (currentTimeInfo.getTimeInfo() != null || currentTimeInfo.getPeriodType() != null) {
                UnionWarActivityServerProto.UnionBattleDataStatisticsReqMsg.Builder crossReq = UnionWarActivityServerProto.UnionBattleDataStatisticsReqMsg.newBuilder();
                crossReq.setActivityId(activityId);
                crossReq.setPhase(phase);
                crossReq.setSession(session);
                player.sendUnionActivityGroupPacket(Protocol.C_UNION_WAR_PREPARE_BATTLE_DATA_STATISTICS, crossReq, unionWar.getActivityInfo().getActivityId(), groupId);
            }

        }
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
